package com.icesoft;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.scheduling.annotation.EnableAsync;

import java.net.InetAddress;
import java.nio.charset.Charset;

@Slf4j
@EnableAsync
@Configuration
@EnableCaching
@ServletComponentScan
@SpringBootApplication(exclude = {FreeMarkerAutoConfiguration.class})
public class Application {

	public static void main(String[] args) {

		try {
			if (!"UTF-8".equals(Charset.defaultCharset().name())) {
				log.error("启动命令错误，默认编码不是UTF8，启动时指定：-Dfile.encoding=UTF-8");
				System.exit(0);
			}

			ConfigurableApplicationContext context = SpringApplication.run(Application.class, args);
			ConfigurableEnvironment environment = context.getEnvironment();
			String port = environment.getProperty("server.port");
			String hostAddress = InetAddress.getLocalHost().getHostAddress();
			String contextPath = environment.getProperty("server.servlet.context-path");
			System.out.println("\u001b[0m  _                            __  _   \n(_)                          / _|| |  \n _   ___   ___   ___   ___  | |_ | |_ \n| | / __| / _ \\ / __| / _ \\ |  _|| __|\n| || (__ |  __/ \\__ \\| (_) || |  | |_ \n|_| \\___| \\___| |___/ \\___/ |_|   \\__|\n                                      \n");
			System.out.println("\u001b[32m :: Ice Soft Boot ::                (v1.0.0)\n");
			System.out.println("\u001b[0m App running at:");
			System.out.println("\u001b[0m - Local:   http://localhost:" + port + contextPath);
			System.out.println("\u001b[0m - Network: http://" + hostAddress + ":" + port + contextPath);
			System.out.println();
		} catch (Exception var6) {
			var6.printStackTrace();
		}

	}

}
